package gp;

import firing.FiringTree;
import game.GameBoard;

import java.util.Collections;
import java.util.List;

public class HarbingerOfHeuristics {
    
    //2 minutes of frames
    public static final int FRAMES_PER_TEST = 5 * 3600; 
    
    public static int getHeuristic(GameBoard game) {
	return game.playerDamage - game.enemy.getWastedEnergy()/10 + game.nearHits * 10 - game.bulletProximityPenalty;
	//return 100 * game.playerDamage + game.enemyBulletsFired;
    }
    
    /** Assesses each tree's heuristic value, then sorts the list */
    public static void getHeuristic(List<FiringTree> population) {
	GameBoard tester = new GameBoard(null); //we aren't using keybindings, so no need to put in keystate
	tester.setAdvancedPlayerAI(true);
	for(FiringTree t:population) {
	    tester.setTree(t);
	    tester.enemy.resetWastedEnergy();
	    for(int i=0;i<FRAMES_PER_TEST;i++) {
		tester.update();
	    }
	    //System.out.println("Heuristic: " + getHeuristic(tester));
	    t.setHeuristic(getHeuristic(tester));
	}
	//note: higher ranked trees have larger indexes
	Collections.sort(population);
    }
}
